package com.huluobo.a2206douyindemo.mvvmdemo;

import androidx.lifecycle.MutableLiveData;

import com.huluobo.a2206douyindemo.mvpdemo.UserBean;

/**
 * Created by LC on 2024/8/14.
 * Repo:repository (数据仓库),用来代替model,因为在MVVM模式中,有个VM层,名字相同,容易混淆
 * 所以用Repo来代替,本质上都是数据仓库
 * MutableLiveData  LiveData的变种,Mutable是可变的意思
 */
public class LoginDemoRepo {
    public void login(String username, String password, MutableLiveData<UserBean> success,
                      MutableLiveData<String> failed) {
        if (username.equals("lc") && password.equals("123")) {
            //模拟网络请求,当成功时,给liveData赋值
            success.setValue(new UserBean(username, password));
//            success.postValue(new UserBean(username, password));
        } else {
            failed.setValue("用户名密码不匹配");
        }
    }
}
